/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#ifndef OBSPLUGIN_APPSERVICE_H
#define OBSPLUGIN_APPSERVICE_H
// PluginSDK
#include "ApplicationService.h"
#include "storage/huawei/HWCloudService.h"
#include "storage/alibaba/ALiCloudService.h"
#include "common/JsonHelper.h"
#include "common/CleanMemPwd.h"

namespace AppServiceExport {
struct AuthExtendInfo {
    int storageType{0};
    std::string ak;
    std::string sk;
    std::string useHttps;
    std::string endPoint;
    std::string proxyEnable;
    std::string proxyHostName;
    std::string proxyUserName;
    std::string proxyUserPwd;
    std::string certification;
    ~AuthExtendInfo()
    {
        Module::CleanMemoryPwd(sk);
        Module::CleanMemoryPwd(proxyUserPwd);
        Module::CleanMemoryPwd(certification);
    }
    BEGIN_SERIAL_MEMEBER
    SERIAL_MEMBER_TO_SPECIFIED_NAME(storageType, storageType)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(ak, ak)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(sk, sk)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(useHttps, useHttps)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(endPoint, endpoint)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(proxyEnable, proxyEnable)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(proxyHostName, proxyHostName)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(proxyUserName, proxyUserName)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(proxyUserPwd, proxyUserPwd)
    SERIAL_MEMBER_TO_SPECIFIED_NAME(certification, certification)
    END_SERIAL_MEMEBER
};

struct ApplicationExtendInfo {
    std::string storageType;
    BEGIN_SERIAL_MEMEBER
    SERIAL_MEMBER_TO_SPECIFIED_NAME(storageType, storageType)
    END_SERIAL_MEMEBER
};

/**
 * check application exist with authentication, synchronization function
 * application: check application information
 * auth: application authentication
 *
 * @param application
 * @param auth
 */
void CheckApplication(ActionResult &returnValue, const ApplicationEnvironment &appEnv, const Application &application);

/**
 * Function description
 *     list appliation resource by page, synchronization function, .eg query data file of database
 * Parameters
 *     appEnv : protect application environment
 *     application : check application information
 *     parentResource : query child resource of the parentResource
 *     condition : query conditions
 * Return value
 *     application resource list in the host with one page, list is empty when no application resource exists
 * @param request
 */
void ListApplicationResourceV2(
    AppProtect::ResourceResultByPage &returnValue, const AppProtect::ListResourceRequest &request);
int Decrypt(std::string &plainText, const std::string &cipherText);
int Encrypt(const std::string &plainText, std::string &cipherText);
void TransformCloudServiceMsg(Module::StorageVerifyInfo &cloudServiceMsg, const AuthExtendInfo &extendInfo);
bool AddIpRule(const Module::StorageVerifyInfo &cloudServiceMsg);
bool InitValue(const Application &application, ActionResult &returnValue, AuthExtendInfo &extendInfo,
    ApplicationExtendInfo &appExtendInfo);
}  // namespace AppServiceExport

#endif  // OBSPLUGIN_APPSERVICE_H
